__author__ = 'tengxue'
import MySQLdb

def mysqlTest1():
    db = MySQLdb.connect("localhost","root","Aa123456","testdb")

    cursor = db.cursor()
    cursor.execute("SELECT VERSION()")

    data = cursor.fetchone()

    print "Database version : %s " % data

    db.close()

    return


def save():
    db=MySQLdb.connect("localhost","root","Aa123456","testdb")

    cursor=db.cursor()

    sql = """INSERT INTO person(name,age)
         VALUES ('dark',10)"""
    try:
        cursor.execute(sql)
        db.commit()
    except:
        db.rollback()
    db.close()

def select():
    db=MySQLdb.connect("localhost","root","Aa123456","testdb")
    cursor=db.cursor()
    sql="""select * from person"""
    try:
        cursor.execute(sql)
        result=cursor.fetchall()
        for row in result:
            id=row[0]
            name=row[1]
            age=row[2]
            print "id:",id,";name:",name,";age:",age
    except:
        print "select has error"

    finally:
        db.close()

select()



